<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/table.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/dwz/themes/default/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="${pageContext.request.contextPath}/dwz/themes/css/core.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery-2.1.4.min.js"></script>
<table border="0" cellpadding="0" cellspacing="0" class="table_border">
	<tr>
		<td>
			<table width="100%" border="0" cellpadding="0" cellspacing="0"
				class="table_right">
				<tr>
					<td><font style="font-size: 12px;"><strong>修改许可</strong></font>
					</td>
					<td width="25" height="26" align="left"></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<form id="add_permission">
				<table width="100%" border="0" cellspacing="0" class="table_right">
				<tr>
					<td align="center">
						<table border="0" cellpadding="0" cellspacing="0"
							class="box_table" id="box_table2">
							<thead>
								<tr>
									<td height="36" class="box_table_even">代码：</td>
									<input type="text" style="display: none" id="id" name="id">
									<input type="text" style="display: none" id="pid" name="pId">
									<td class="box_table_odd"><input id="code" name="code" type="text" />
										<span class="star">*</span>
									</td>
								</tr>
								<tr>
									<td height="36" class="box_table_even">名称：</td>
									<td class="box_table_odd"><input id="name" name="name" type="text" /> <span
										class="star">*</span></td>
								</tr>
								<tr>
									<td class="box_table_even">模块URL：</td>
									<td class="box_table_odd"><input id="moduleUrl" name="moduleUrl" type="text" /></td>
								</tr>
								<tr>
									<td class="box_table_even">操作URL：</td>
									<td class="box_table_odd"><input id="operationUrl" name="operationUrl" type="text" size="90" />
										多个逗号隔开</td>
								</tr>
								<tr>
									<td class="box_table_even">排序号：</td>
									<td class="box_table_odd"><input id="orderNo" name="orderNo" type="text" /> </td>
								</tr>
							</thead>
							<tbody>
							</tbody>
						</table>

						<table border="0" cellpadding="0" cellspacing="0"
							class="operation">
							<thead>
								<tr>
									<td height="24">&nbsp;</td>
								</tr>
							</thead>
						</table>
					</td>
				</tr>
			</table>
			</form>
		</td>
	</tr>
	<tr>
		<td>
			<table width="100%" border="0" cellpadding="0" cellspacing="0"
				class="table_padding">
				<tr>
					<td height="21" align="right">
						<table align="left">
							<tr>
								<td width="50px"><a class="button" onclick="updatePermission()"><span>更新</span></a></td>
								<td width="50px"><a class="button"
									href="javascript:void(window.history.back());"><span>返回</span></a></td>
								<td id="erroeMsg" style="color: red;"></td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

<script>
	let zTreeObj = parent.treeFrame.$.fn.zTree.getZTreeObj("permission_tree");
	var nodes = zTreeObj.getSelectedNodes();
	let id = nodes[0].id;

	//获取表单的json对象
	function getParame(curform) {
		let serializeArray = curform.serializeArray();
		var parame = new Object();

		for (let i = 0; i < serializeArray.length; i++) {
			let name = serializeArray[i].name;
			let value = serializeArray[i].value;
			parame[name] = value;
		}
		return parame;
	}

	//发送异步请求获取权限的信息
	$.post("getPermissionBuId",{id:id},function (data) {
		console.log("得到数据："+data);
		$("#code").val(data.code);
		$("#id").val(data.id);
		$("#name").val(data.name);
		$("#moduleUrl").val(data.moduleUrl);
		$("#operationUrl").val(data.operationUrl);
		$("#orderNo").val(data.orderNo);
		$("#pid").val(data.pId);
	});

	function updatePermission() {
		//获取表单数据
		let parame = getParame($("#add_permission"));

		$.post("updatePermission",parame,function (data) {
			if(data.status==true){
				location.href = "getPermission?id="+$("#id").val();
			}else {
				$("#erroeMsg").val(data.errorMsg);
			}
		});
	}
</script>
